<?php 
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 
mm_showMyFileName( __FILE__ );
require_once( CLASSPATH . "ps_checkout.php" );
require_once( CLASSPATH . "ps_shipping_method.php" );
$ps_shipping_method = new ps_shipping_method;
$ps_checkout = new ps_checkout;
$user_id = $_SESSION["auth"]["user_id"];
$db =& JFactory::getDBO();
$q = 'SELECT * FROM #__vm_user_info ';
$q.= "WHERE `user_id` = $user_id ";
$db->setQuery($q);
$userinfo = $db->loadObjectList();

if(count($userinfo) == 0){
	echo "<script type='text/javascript'>window.location = 'index.php?option=com_virtuemart'; </script>";
}

$q = "SELECT * FROM #__vm_category WHERE `category_publish` = 'Y'";
$db = JFactory::getDBO();
$db->setQuery($q);
$category = $db->loadObjectList();
$category_id = @JRequest::getInt("category_id",$category[0]->category_id);

$q = "SELECT * FROM #__content WHERE `id` = '51'";
$db->setQuery($q);
$term = $db->loadObjectList();

?>

<div class="containerUnder">
	<form id="haForm" method="POST" action="index.php?option=com_virtuemart&page=checkout.payment">
		<div class="cartLeft">
			<div class="mainTitle"><?php echo $VM_LANG->_('HA_SHOPPING_CART'); ?></div>
			<ul class="cartCategory">
				<?php 
					for($i=0;$i<count($category);$i++){
						if($category_id != $category[$i]->category_id ){
							echo "<li><a href=\"index.php?option=com_virtuemart&page=shop.list&category_id=".$category[$i]->category_id."&Itemid=".$Itemid."\" class=\"cartCategory\">".$category[$i]->category_name."</a></li>";
						}else{
							echo "<li><a id=\"catSelect\" href=\"index.php?option=com_virtuemart&page=shop.list&category_id=".$category[$i]->category_id."\" class=\"cartCategory\">".$category[$i]->category_name."</a></li>";
						}
					}
				?>
			</ul>
		</div>
		<div class="cartRight">
			<div class="step1">
				<ul>
					<li><p><span>1</span><?php echo $VM_LANG->_('HA_STEP_1'); ?></p></li>
					<li><p><span>2</span><?php echo $VM_LANG->_('HA_STEP_2'); ?></p></li>
					<li class="select-step"><p><span>3</span><?php echo $VM_LANG->_('HA_STEP_3'); ?></p></li>
					<li><p><span>4</span><?php echo $VM_LANG->_('HA_STEP_4'); ?></p></li>
				</ul>
			</div>
			
			<div class="cartButton">
				
			   
			<div class="orderCenter">
				<div class="orderTitle"><!--<span>3A</span>--><?php echo $VM_LANG->_('HA_DELIVERY_TYPE'); ?></div>
				<!-- <div class="orderSubTitle">Levering og håndtering</div>
				 
				<input type="radio" checked="checked"/> Pakkepost DKK 50,00<br/>
				<input type="radio"/> Erhverv DKK 30,00<br/><br/>-->
				<?php 
					//$theme = new $GLOBALS['VM_THEMECLASS']();
					//echo $theme->fetch( 'checkout/get_shipping_method.tpl.php');
					/*echo "<pre>";
					var_dump(ps_shipping_method::method_list());
					echo "</pre>";*/
					//echo $VM_LANG->_('HA_SHIPPING_METHOD_LB')."<br />";
					
					ps_checkout::list_shipping_methods();
				?>
				<!-- ... -->
			</div>
			<div class="orderCenter ml70">
				<div class="orderTitle"><!--<span>3B</span>--><?php echo $VM_LANG->_('HA_PAYMENT_METHOD'); ?></div>
				<?php 
					echo $term[0]->introtext.$term[0]->fulltext;
				?>
				<img src="<?php echo JURI::base(); ?>templates/rhuk_milkyway/images/pay-icon.jpg" alt=""/>
			</div>
			  <div class="clr space20"></div>
			<div class="cartButtonLeft">
					<img src="<?php echo JURI::base(); ?>templates/rhuk_milkyway/images/back_ico.jpg" alt=""/><a style="cursor:pointer" onclick="window.history.back();"> <?php echo $VM_LANG->_('HA_BACK_BTN');?></a>
				</div>
				 <div class="cartButtonRight"><a id="ha-btn-submit" class="btn btn-til" href="#"><span><?php echo $VM_LANG->_('HA_EXECUTE_PAYMENT'); ?></span></a></div>                  
				<div class="clr space20"></div>
				<!--<div>
					<a href="#"><img src="<?php echo JURI::base(); ?>templates/rhuk_milkyway/images/footer_banner.jpg" alt=""/></a>
				</div>-->

			</div>
			<div class="cartInfo">
				<div class="cartInfoTxt">Pay by Dankort, Visa, Visa Electron, Mastercard og Maestro</div>
				<img src="<?php echo JURI::base(); ?>templates/rhuk_milkyway/images/pay-icon.jpg" alt=""/>                    
				<div class="clr"></div>
			</div>
		</div>
		
		<div class="clr"></div>
		<input type="hidden" name="checkout_last_step" value="2" />
		<input type="hidden" name="checkout_this_step[]" value="CHECK_OUT_GET_SHIPPING_METHOD" />
		<input type="hidden" name="formSubmit" value="Next >>" />
		<input type="hidden" name="func" value="checkoutProcess" />
		<input type="hidden" name="payment_method_id" value="0" />
		<input type="hidden" name="user_id" value="<?php echo $user_id ?>" />
		<input type="hidden" name="zone_qty" value="1" />
		<input type="hidden" name="ship_to_info_id" value="" />
		<input type="hidden" name="ship_to_info_id" value="<?php echo $userinfo[0]->user_info_id; ?>" />
		<input type="hidden" name="shipping_rate_id" value="" />
		<input type="hidden" id="ha-shipping_rate_id" name="shipping_rate_id" value="" />
	</form>
</div>
<script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery('#ha-btn-submit').click(function(){
			//alert('a');
			jQuery('input[name|="shipping_rate_id"]').each(function (i) {
				if(jQuery(this).is(':checked') == true){
					var ship_rate_id = jQuery(this).attr("value");
					//alert(ship_rate_id);
					jQuery("#ha-shipping_rate_id").attr("value",ship_rate_id);
					$('#haForm').submit();
				}
			});
		});
		
	});
</script>